/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * File Name          : app_freertos.c
  * Description        : Code for freertos applications
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2025 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "FreeRTOS.h"
#include "task.h"
#include "main.h"
#include "cmsis_os.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "usr_inc.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */

/* USER CODE END Variables */
/* Definitions for defaultTask */
osThreadId_t defaultTaskHandle;
const osThreadAttr_t defaultTask_attributes = {
  .name = "defaultTask",
  .priority = (osPriority_t) osPriorityLow,
  .stack_size = 400 * 4
};
/* Definitions for tossCmdDeal */
osThreadId_t tossCmdDealHandle;
const osThreadAttr_t tossCmdDeal_attributes = {
  .name = "tossCmdDeal",
  .priority = (osPriority_t) osPriorityHigh,
  .stack_size = 240 * 4
};
/* Definitions for dribbleCmdDeal */
osThreadId_t dribbleCmdDealHandle;
const osThreadAttr_t dribbleCmdDeal_attributes = {
  .name = "dribbleCmdDeal",
  .priority = (osPriority_t) osPriorityHigh,
  .stack_size = 240 * 4
};
/* Definitions for nrfUpdate */
osThreadId_t nrfUpdateHandle;
const osThreadAttr_t nrfUpdate_attributes = {
  .name = "nrfUpdate",
  .priority = (osPriority_t) osPriorityHigh,
  .stack_size = 600 * 4
};
/* Definitions for chassisPrintf */
osThreadId_t chassisPrintfHandle;
const osThreadAttr_t chassisPrintf_attributes = {
  .name = "chassisPrintf",
  .priority = (osPriority_t) osPriorityLow7,
  .stack_size = 400 * 4
};
/* Definitions for joyExe */
osThreadId_t joyExeHandle;
const osThreadAttr_t joyExe_attributes = {
  .name = "joyExe",
  .priority = (osPriority_t) osPriorityNormal,
  .stack_size = 600 * 4
};
/* Definitions for chassisSendVel */
osThreadId_t chassisSendVelHandle;
const osThreadAttr_t chassisSendVel_attributes = {
  .name = "chassisSendVel",
  .priority = (osPriority_t) osPriorityAboveNormal,
  .stack_size = 400 * 4
};
/* Definitions for chassisPointExe */
osThreadId_t chassisPointExeHandle;
const osThreadAttr_t chassisPointExe_attributes = {
  .name = "chassisPointExe",
  .priority = (osPriority_t) osPriorityNormal,
  .stack_size = 240 * 4
};
/* Definitions for chassisYawExe */
osThreadId_t chassisYawExeHandle;
const osThreadAttr_t chassisYawExe_attributes = {
  .name = "chassisYawExe",
  .priority = (osPriority_t) osPriorityNormal,
  .stack_size = 240 * 4
};
/* Definitions for chassisCmdDeal */
osThreadId_t chassisCmdDealHandle;
const osThreadAttr_t chassisCmdDeal_attributes = {
  .name = "chassisCmdDeal",
  .priority = (osPriority_t) osPriorityHigh,
  .stack_size = 240 * 4
};
/* Definitions for LocMerge */
osThreadId_t LocMergeHandle;
const osThreadAttr_t LocMerge_attributes = {
  .name = "LocMerge",
  .priority = (osPriority_t) osPriorityNormal,
  .stack_size = 500 * 4
};
/* Definitions for aimUpdate */
osThreadId_t aimUpdateHandle;
const osThreadAttr_t aimUpdate_attributes = {
  .name = "aimUpdate",
  .priority = (osPriority_t) osPriorityHigh,
  .stack_size = 240 * 4
};
/* Definitions for aimExe */
osThreadId_t aimExeHandle;
const osThreadAttr_t aimExe_attributes = {
  .name = "aimExe",
  .priority = (osPriority_t) osPriorityNormal,
  .stack_size = 300 * 4
};
/* Definitions for battleCmdDeal */
osThreadId_t battleCmdDealHandle;
const osThreadAttr_t battleCmdDeal_attributes = {
  .name = "battleCmdDeal",
  .priority = (osPriority_t) osPriorityHigh,
  .stack_size = 300 * 4
};
/* Definitions for keyCmdDeal */
osThreadId_t keyCmdDealHandle;
const osThreadAttr_t keyCmdDeal_attributes = {
  .name = "keyCmdDeal",
  .priority = (osPriority_t) osPriorityHigh,
  .stack_size = 240 * 4
};
/* Definitions for chassisCalVel */
osThreadId_t chassisCalVelHandle;
const osThreadAttr_t chassisCalVel_attributes = {
  .name = "chassisCalVel",
  .priority = (osPriority_t) osPriorityNormal,
  .stack_size = 240 * 4
};
/* Definitions for chassisGetBias */
osThreadId_t chassisGetBiasHandle;
const osThreadAttr_t chassisGetBias_attributes = {
  .name = "chassisGetBias",
  .priority = (osPriority_t) osPriorityNormal,
  .stack_size = 240 * 4
};
/* Definitions for pidArgsQueue */
osMessageQueueId_t pidArgsQueueHandle;
const osMessageQueueAttr_t pidArgsQueue_attributes = {
  .name = "pidArgsQueue"
};
/* Definitions for tossCmdQueue */
osMessageQueueId_t tossCmdQueueHandle;
const osMessageQueueAttr_t tossCmdQueue_attributes = {
  .name = "tossCmdQueue"
};
/* Definitions for tossStrokeQueue */
osMessageQueueId_t tossStrokeQueueHandle;
const osMessageQueueAttr_t tossStrokeQueue_attributes = {
  .name = "tossStrokeQueue"
};
/* Definitions for dribbleCmdQueue */
osMessageQueueId_t dribbleCmdQueueHandle;
const osMessageQueueAttr_t dribbleCmdQueue_attributes = {
  .name = "dribbleCmdQueue"
};
/* Definitions for locaterMsgBox */
osMessageQueueId_t locaterMsgBoxHandle;
const osMessageQueueAttr_t locaterMsgBox_attributes = {
  .name = "locaterMsgBox"
};
/* Definitions for joyMsgQueue */
osMessageQueueId_t joyMsgQueueHandle;
const osMessageQueueAttr_t joyMsgQueue_attributes = {
  .name = "joyMsgQueue"
};
/* Definitions for chassisJoyVelMsgBox */
osMessageQueueId_t chassisJoyVelMsgBoxHandle;
const osMessageQueueAttr_t chassisJoyVelMsgBox_attributes = {
  .name = "chassisJoyVelMsgBox"
};
/* Definitions for chassisPointVelMsgBox */
osMessageQueueId_t chassisPointVelMsgBoxHandle;
const osMessageQueueAttr_t chassisPointVelMsgBox_attributes = {
  .name = "chassisPointVelMsgBox"
};
/* Definitions for chassisYawVelMsgBox */
osMessageQueueId_t chassisYawVelMsgBoxHandle;
const osMessageQueueAttr_t chassisYawVelMsgBox_attributes = {
  .name = "chassisYawVelMsgBox"
};
/* Definitions for chassisCmdQueue */
osMessageQueueId_t chassisCmdQueueHandle;
const osMessageQueueAttr_t chassisCmdQueue_attributes = {
  .name = "chassisCmdQueue"
};
/* Definitions for radarLoc */
osMessageQueueId_t radarLocHandle;
const osMessageQueueAttr_t radarLoc_attributes = {
  .name = "radarLoc"
};
/* Definitions for chassisPointCmdQueue */
osMessageQueueId_t chassisPointCmdQueueHandle;
const osMessageQueueAttr_t chassisPointCmdQueue_attributes = {
  .name = "chassisPointCmdQueue"
};
/* Definitions for chassisYawCmdQueue */
osMessageQueueId_t chassisYawCmdQueueHandle;
const osMessageQueueAttr_t chassisYawCmdQueue_attributes = {
  .name = "chassisYawCmdQueue"
};
/* Definitions for aimModeQueue */
osMessageQueueId_t aimModeQueueHandle;
const osMessageQueueAttr_t aimModeQueue_attributes = {
  .name = "aimModeQueue"
};
/* Definitions for shootArgsQueue */
osMessageQueueId_t shootArgsQueueHandle;
const osMessageQueueAttr_t shootArgsQueue_attributes = {
  .name = "shootArgsQueue"
};
/* Definitions for battleCmdQueue */
osMessageQueueId_t battleCmdQueueHandle;
const osMessageQueueAttr_t battleCmdQueue_attributes = {
  .name = "battleCmdQueue"
};
/* Definitions for keyCmdQueue */
osMessageQueueId_t keyCmdQueueHandle;
const osMessageQueueAttr_t keyCmdQueue_attributes = {
  .name = "keyCmdQueue"
};
/* Definitions for chassisActVelBox */
osMessageQueueId_t chassisActVelBoxHandle;
const osMessageQueueAttr_t chassisActVelBox_attributes = {
  .name = "chassisActVelBox"
};

/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */

/* USER CODE END FunctionPrototypes */

void StartDefaultTask(void *argument);
extern void StartTossCmdDeal(void *argument);
extern void StartDribbleCmdDeal(void *argument);
extern void StartNrfUpdate(void *argument);
extern void StartChassisPrintf(void *argument);
extern void StartJoyExe(void *argument);
extern void StartChassisSendVel(void *argument);
extern void StartChassisPointExe(void *argument);
extern void StartChassisYawExe(void *argument);
extern void StartChassisCmdDeal(void *argument);
extern void StartLocMerge(void *argument);
extern void StartAimUpdate(void *argument);
extern void StartAimExe(void *argument);
extern void StartBattleCmdDeal(void *argument);
extern void StartKeyCmdDeal(void *argument);
extern void StartChassisCalVel(void *argument);
extern void StartChassisGetBias(void *argument);

void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */

/**
  * @brief  FreeRTOS initialization
  * @param  None
  * @retval None
  */
void MX_FREERTOS_Init(void) {
  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* USER CODE BEGIN RTOS_MUTEX */
  /* add mutexes, ... */
  /* USER CODE END RTOS_MUTEX */

  /* USER CODE BEGIN RTOS_SEMAPHORES */
  /* add semaphores, ... */
  /* USER CODE END RTOS_SEMAPHORES */

  /* USER CODE BEGIN RTOS_TIMERS */
  /* start timers, add new ones, ... */
  /* USER CODE END RTOS_TIMERS */

  /* Create the queue(s) */
  /* creation of pidArgsQueue */
  pidArgsQueueHandle = osMessageQueueNew (8, sizeof(PidArgsMsg_t), &pidArgsQueue_attributes);

  /* creation of tossCmdQueue */
  tossCmdQueueHandle = osMessageQueueNew (8, sizeof(TossCmdMsg_t), &tossCmdQueue_attributes);

  /* creation of tossStrokeQueue */
  tossStrokeQueueHandle = osMessageQueueNew (8, sizeof(float), &tossStrokeQueue_attributes);

  /* creation of dribbleCmdQueue */
  dribbleCmdQueueHandle = osMessageQueueNew (8, sizeof(DribbleCmdMsg_t), &dribbleCmdQueue_attributes);

  /* creation of locaterMsgBox */
  locaterMsgBoxHandle = osMessageQueueNew (1, sizeof(LocaterMsg_t), &locaterMsgBox_attributes);

  /* creation of joyMsgQueue */
  joyMsgQueueHandle = osMessageQueueNew (16, sizeof(JoyStickMsg_t), &joyMsgQueue_attributes);

  /* creation of chassisJoyVelMsgBox */
  chassisJoyVelMsgBoxHandle = osMessageQueueNew (1, sizeof(VelMsg_t), &chassisJoyVelMsgBox_attributes);

  /* creation of chassisPointVelMsgBox */
  chassisPointVelMsgBoxHandle = osMessageQueueNew (1, sizeof(VelMsg_t), &chassisPointVelMsgBox_attributes);

  /* creation of chassisYawVelMsgBox */
  chassisYawVelMsgBoxHandle = osMessageQueueNew (1, sizeof(VelMsg_t), &chassisYawVelMsgBox_attributes);

  /* creation of chassisCmdQueue */
  chassisCmdQueueHandle = osMessageQueueNew (8, sizeof(ChassisCmdMsg_t), &chassisCmdQueue_attributes);

  /* creation of radarLoc */
  radarLocHandle = osMessageQueueNew (1, sizeof(LocaterMsg_t), &radarLoc_attributes);

  /* creation of chassisPointCmdQueue */
  chassisPointCmdQueueHandle = osMessageQueueNew (8, sizeof(PointMsg_t), &chassisPointCmdQueue_attributes);

  /* creation of chassisYawCmdQueue */
  chassisYawCmdQueueHandle = osMessageQueueNew (8, sizeof(float), &chassisYawCmdQueue_attributes);

  /* creation of aimModeQueue */
  aimModeQueueHandle = osMessageQueueNew (8, sizeof(AimMode_t), &aimModeQueue_attributes);

  /* creation of shootArgsQueue */
  shootArgsQueueHandle = osMessageQueueNew (8, sizeof(ShootArgsMsg_t), &shootArgsQueue_attributes);

  /* creation of battleCmdQueue */
  battleCmdQueueHandle = osMessageQueueNew (8, sizeof(BattleCmdMsg_t), &battleCmdQueue_attributes);

  /* creation of keyCmdQueue */
  keyCmdQueueHandle = osMessageQueueNew (8, sizeof(uint8_t), &keyCmdQueue_attributes);

  /* creation of chassisActVelBox */
  chassisActVelBoxHandle = osMessageQueueNew (1, sizeof(VelMsg_t), &chassisActVelBox_attributes);

  /* USER CODE BEGIN RTOS_QUEUES */
  /* add queues, ... */
  /* USER CODE END RTOS_QUEUES */

  /* Create the thread(s) */
  /* creation of defaultTask */
  defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);

  /* creation of tossCmdDeal */
  tossCmdDealHandle = osThreadNew(StartTossCmdDeal, NULL, &tossCmdDeal_attributes);

  /* creation of dribbleCmdDeal */
  dribbleCmdDealHandle = osThreadNew(StartDribbleCmdDeal, NULL, &dribbleCmdDeal_attributes);

  /* creation of nrfUpdate */
  nrfUpdateHandle = osThreadNew(StartNrfUpdate, NULL, &nrfUpdate_attributes);

  /* creation of chassisPrintf */
  chassisPrintfHandle = osThreadNew(StartChassisPrintf, NULL, &chassisPrintf_attributes);

  /* creation of joyExe */
  joyExeHandle = osThreadNew(StartJoyExe, NULL, &joyExe_attributes);

  /* creation of chassisSendVel */
  chassisSendVelHandle = osThreadNew(StartChassisSendVel, NULL, &chassisSendVel_attributes);

  /* creation of chassisPointExe */
  chassisPointExeHandle = osThreadNew(StartChassisPointExe, NULL, &chassisPointExe_attributes);

  /* creation of chassisYawExe */
  chassisYawExeHandle = osThreadNew(StartChassisYawExe, NULL, &chassisYawExe_attributes);

  /* creation of chassisCmdDeal */
  chassisCmdDealHandle = osThreadNew(StartChassisCmdDeal, NULL, &chassisCmdDeal_attributes);

  /* creation of LocMerge */
  LocMergeHandle = osThreadNew(StartLocMerge, NULL, &LocMerge_attributes);

  /* creation of aimUpdate */
  aimUpdateHandle = osThreadNew(StartAimUpdate, NULL, &aimUpdate_attributes);

  /* creation of aimExe */
  aimExeHandle = osThreadNew(StartAimExe, NULL, &aimExe_attributes);

  /* creation of battleCmdDeal */
  battleCmdDealHandle = osThreadNew(StartBattleCmdDeal, NULL, &battleCmdDeal_attributes);

  /* creation of keyCmdDeal */
  keyCmdDealHandle = osThreadNew(StartKeyCmdDeal, NULL, &keyCmdDeal_attributes);

  /* creation of chassisCalVel */
  chassisCalVelHandle = osThreadNew(StartChassisCalVel, NULL, &chassisCalVel_attributes);

  /* creation of chassisGetBias */
  chassisGetBiasHandle = osThreadNew(StartChassisGetBias, NULL, &chassisGetBias_attributes);

  /* USER CODE BEGIN RTOS_THREADS */
  /* add threads, ... */
  /* USER CODE END RTOS_THREADS */

  /* USER CODE BEGIN RTOS_EVENTS */
  /* add events, ... */
  /* USER CODE END RTOS_EVENTS */

}

/* USER CODE BEGIN Header_StartDefaultTask */
/**
  * @brief  Function implementing the defaultTask thread.
  * @param  argument: Not used
  * @retval None
  */
/* USER CODE END Header_StartDefaultTask */
__weak void StartDefaultTask(void *argument)
{
  /* USER CODE BEGIN StartDefaultTask */
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END StartDefaultTask */
}

/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */

/* USER CODE END Application */

